%--------------------------------------------------------------------------
% computes the inner product using the comp trap rule.
% corresponds with the method of integration in the adjoint problem

function v = ip(f1, f2, h, p)

f = f1 .* f2;

if nargin < 3
    h = 1;
end

z = linspace(0, h, p.N);
dz = z(2) - z(1);

v = f(1) + f(p.N);
for i = 2:p.N - 1
    v = v + 2 * f(i);
end

v = v * dz / 2;